<?php
$this->breadcrumbs=array(
	'Articles'=>array('index'),
	$model->arc_id=>array('view','id'=>$model->arc_id),
	'Update',
);

$this->menu=array(
	array('label'=>'List Article', 'url'=>array('index')),
	array('label'=>'Create Article', 'url'=>array('create')),
	array('label'=>'View Article', 'url'=>array('view', 'id'=>$model->arc_id)),
	array('label'=>'Manage Article', 'url'=>array('admin')),
);
?>
<?php 

 	$add_category_url = $this->createUrl('category/createremote');
 	$add_category_type = Category::CATEGORY_NEWS;
 	
	$ready = <<<READY
//	var str = "这里填写文章标题";
//	$("#Article_arc_title").val(str).focus(function(){
//		if($(this).val()==str){
//			$(this).val("");
//		}		
//	});

	$(".category input[type=checkbox]").change(function(){
//		alert($(this).val());
		var str = "";
		$(".category input[type=checkbox]").each(function(){
			if($(this).attr("checked") == true){
				str += ","+$(this).val();
			}
		});

		str = str.substring(1,str.length);
		$("#Article_arc_cids").val(str);
		
//		alert(str);

	});

	$("#arc_submit").button();
	$("#get_tag").button();
	$("#add_category").button();
	
	$("#add_category").click(function(){
		$.post("$add_category_url",{
			'cate_pid':$("#Article_arc_cids").val(),
			'cate_name':$("#categoryName").val(),
			'cate_type':$add_category_type
		},function(msg){
//			alert(msg);
			$(".category").append(msg);

			$.getJSON("{$this->createUrl('category/categories')}",function(msg){
// 	            alert(msg);

	            				
	            var pid = document.getElementById("Article_arc_cid");

	            //清除所有已有选项
	            while(pid.childNodes.length>0){
	            	pid.removeChild(pid.childNodes[0]);
	           }
	           $.each(msg,function(k,v){
//					dd += (k+v);

	            					
	            	var option = new Option(v,k);
	            	pid.options.add(option);
	            });
//	            alert(dd);
	    	});

		});
	});
READY;

$analysis_url = $this->createUrl('analysis');
$head_js = <<<HEAD
	function showNext(object){
		object.next().slideToggle("slow");
		return false;
	}
	function getTag(){
	//	alert("Hello");
	//	content = $(document.getElementsByTagName('iframe')[0].contentWindow.document.body).html();
	//	content = $("#el-rte-editor").contents().find("body").html();
	//	content = $(document.getElementsByTagName('iframe')[0]).contents().find("body").html();
		content = $("#Article_arc_content").val();
//		alert(content);
		
		$.post('$analysis_url',{'content':content},function(msg){
			$("#Article_arc_tags").val(msg);
//			alert(msg);
		});
	}
HEAD;
?>

<?php Yii::app()->getClientScript()->registerScript('news-admin-create-ready',$ready,CClientScript::POS_READY);?>
<?php Yii::app()->getClientScript()->registerScript('news-admin-create-heade',$head_js,CClientScript::POS_HEAD);?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'article-form',
	'enableAjaxValidation'=>true,
)); ?>
<div class="column1" style="width:68%;">
	<div class="box">		
		<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20')).'&nbsp;&nbsp;文章恢复',	));?>
			<div class="box-content">
					<!-- 
						<p class="note">Fields with <span class="required">*</span> are required.</p>
					-->
					<?php echo $form->errorSummary($model); ?>			
			
					<?php echo $this->renderPartial('_form', array('model'=>$model,'form'=>$form)); ?>
			</div>	
		<?php $this->endWidget();?>
	</div>
</div>
<div class="column2 form" style="margin-left:70%;width:32%;">
	<textarea rows="3" style="display:none;" cols="20" id="Article_arc_result" name="Article[arc_result]">

	</textarea>
<div class="box">
	<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20')).'&nbsp;&nbsp;'.Yii::t('article','Publish')));?>
	<div class="box-content">
     	<div class="row">
    		<?php echo Yii::t('article','State')?>*：&nbsp;&nbsp;<span id="statelabel"><?php echo Article::model()->getNewsState($model->arc_state);?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_state',Article::model()->generateStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_state'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Comment')?>*：&nbsp;&nbsp;<span id="commentlabel"><?php echo Article::model()->getCommentState($model->arc_isrecommend);?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_iscomment',Article::model()->generateCommentStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_iscomment'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Recommend');?>*：&nbsp;&nbsp;<span id="recommendlabel"><?php echo Article::model()->getRecommendState($model->arc_isrecommend);?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_isrecommend',Article::model()->generateRecommendStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_isrecommend'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Time');?>*：&nbsp;&nbsp;<span id="timelabel"><?php echo date('Y-m-d H:i:s',time());?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">
    			<?php echo $form->textField($model,'arc_created',array('value'=>date('Y-m-d H:i:s',time()))); ?>
    			<?php echo $form->error($model,'arc_created'); ?>		
    		</div>
    
    	</div>
    </div>
	<?php $this->endWidget();?>
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'',
		));
	?>	
		<div class="box-content" style="height:30px;">
			<?php if($model->isNewRecord):?>
				<button type="submit" id="arc_submit" class="right" >Create</button> 
			<?php else:?>
				<button type="submit" id="arc_submit" class="right" >Update</button> 
			<?php endif;?>	
		</div>
	<?php $this->endWidget();?>
	
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Tags',
		));
	?>	
    <div class="row">
    	<?php echo $form->textField($model,'arc_tags',array('style'=>'width:60%;')); ?>
    	<button type="button" id="get_tag" class="right" onclick="getTag();" >Tags</button> 
    	<?php echo $form->error($model,'arc_tags'); ?>
    </div>	    
	<?php $this->endWidget();?>	
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Category',
		));
	?>
   	<div class="row">
		<?php 
	    	$this->widget('application.components.school.category.articleCategoryList');
	   	?>
    	&nbsp;&nbsp;<span id="categorylabel"><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">增加分类</a>
            
       	<div class="hide">	<br />
               <div class="column1" style="margin:0px;">
                   <?php echo $form->dropDownList($model,'arc_cid',Category::model()->getArticleCategoryDropdownList()); ?>

                   <?php echo $form->error($model,'arc_cid'); ?>
               </div>
	           <div class="column2"  style="padding-top:10px;">
                  <input type="hidden" id="Article_arc_cids" name="Article[arc_cids]"/>	
        		  <input type="text" id="categoryName" name="categoryName" />	
               </div>
                <br />
                <button id="add_category" type="button">Add</button>    		
    	</div>	    
    </div>

	<?php $this->endWidget();?>
</div>
<?php $this->endWidget(); ?>